#! /usr/bin/env python
# If something bad happens, tell HBL to quit
import sys, traceback, psp2d, os
if os.path.exists("ms0:/pygame") == False:
	os.mkdir("ms0:/pygame")
	os.mkdir("ms0:/pygame/tmp")

sys.path.append("ms0:/pygame")

if os.path.exists("config.py") == False:
	open("config.py","w").write(open("CONFIG.TXT","r").read())
if os.path.exists("imports.py") == False:
	open("imports.py","w").write(open("IMPORTS.TXT","r").read())

try: import pymenu
except SystemExit:
	while True: break
except:
	traceback.print_exc()
	scr = psp2d.Screen()
	fnt = psp2d.Font("font.png")
	img = psp2d.Image(480, 272)
	img.clear(psp2d.Color(0,50,255))
	fnt.drawText(img, 0, 0, "BLUE SCREEN OF DEATH!")
	fnt.drawText(img, 0, 30, "The menu has crashed")
	fnt.drawText(img, 0, 60, "For more information see log.txt")
	fnt.drawText(img, 0, 90, "Press cross to exit")
	scr.blit(img)
	scr.swap()
	open("ms0:/path.txt","w").write("quit\n")
	while True:
		pad = psp2d.Controller()
		if pad.cross: break
